using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Fan.Dongping.DataBase;

namespace Fan.Dongping.DataAccess
{
    /// <summary>
    /// 
    /// </summary>
    public class SearchDA
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static DataTable GetWhoesSeach(string userName)
        {
            string sql = "select * from CustomSearch where  UserName=@UserName order by ProNo";
            SqlParameter[] paras = new SqlParameter[1];
            paras[0] = new SqlParameter("@UserName",userName );

            return DA_Base.RunReturnDataset(sql, paras).Tables[0];
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="searchID"></param>
        /// <returns></returns>
        public static bool IsWhoseSearch(string userName,string searchID)
        {
            string sql = "select count(*) from CustomSearch where SearchID=@SearchID and UserName=@UserName";
            SqlParameter[] paras = new SqlParameter[2];
            paras[0] = new SqlParameter("@UserName",userName );
            paras[1] = new SqlParameter("@SearchID", searchID);

            int i=(int) DA_Base.ExecuteScalar(sql, paras) ;
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="searchId"></param>
        /// <returns></returns>
        public static int DeletetSearch(string searchId)
        {
            string sql = "delete  from CustomSearch where  searchId=@searchId ";
            SqlParameter[] paras = new SqlParameter[1];
            paras[0] = new SqlParameter("@searchId",searchId );
            return DA_Base.ExecuteNonQuery(sql, paras);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="summary"></param>
        /// <param name="condition"></param>
        /// <param name="userName"></param>
        public static void AddSearch(string summary,string condition,string userName)
        {
            string sql = "insert into CustomSearch (Summary,Condition,UserName) values (@Summary,@Condition ,@UserName)";
            SqlParameter[] paras = new SqlParameter[3];
            paras[0] = new SqlParameter("@Condition",condition );
            paras[1] = new SqlParameter("@userName", userName);
            paras[2] = new SqlParameter("@Summary",summary );

            DA_Base.ExecuteNonQuery(sql, paras);
        }



    }
}
